﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model;

namespace com.lover.astd.common.logicexe.equip
{
    public class MerchantExe : ExeBase
    {
        public MerchantExe() { _name = ConfigStrings.S_Merchant; _readable = ConfigStrings.SR_Merchant; }
        public override long execute()
        {
            if (_user.Level < 30) return next_day();
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();

            bool only_free = conf.ContainsKey(ConfigStrings.only_free) && conf[ConfigStrings.only_free].ToLower().Equals("true");
            string merchant_type = "马", sell_quality = "红色";
            if (conf.ContainsKey(ConfigStrings.type)) merchant_type = conf[ConfigStrings.type];
            if (conf.ContainsKey(ConfigStrings.sell_quality)) sell_quality = conf[ConfigStrings.sell_quality];
            int silver_available = getSilverAvailable();

            int result = ServiceFactory.getEquipManager().handleMerchants(_proto, _logger, silver_available, only_free, merchant_type, sell_quality);
            if (result == 3) return next_day();
            else if (result == 0) return immediate();
            else return an_hour_later();
        }
    }
}
